Back to course home
0% completed
Vote For New Content
LinkedIn Hard
Max Points on a Line (hard)
Solution: Max Points on a Line
Closest Binary Search Tree Value II (hard)
Solution: Closest Binary Search Tree Value II
Word Ladder (hard)
Solution: Word Ladder
Median of Two Sorted Arrays (hard)
Solution: Median of Two Sorted Arrays
Largest Rectangle in Histogram (hard)
Solution: Largest Rectangle in Histogram
Serialize and Deserialize Binary Tree (hard)
Solution: Serialize and Deserialize Binary Tree
Edit Distance (medium)
Problem Statement
Given two strings word1 and word2, return the least number of edits needed to transform word1 to word2.
You can perform any one edit from below three in a single operation on Word:
Inserta characterDeletea characterReplacea character
Examples
-
Example 1:
- Input: word1 =
"cat", word2 ="cut" - Expected Output: 1
- Justification: Only one operation is needed, replacing 'a' with 'u' in "cat" to make it "cut".
- Input: word1 =
-
Example 2:
- Input: word1 =
"sun", word2 ="satur" - Expected Output: 3
- Justification: Three operations needed: 1) Insert 'a' after 's', 2) Insert 't' after 'a', and 3) Replace 'n' with 'r'.
- Input: word1 =
-
Example 3:
- Input: word1 =
"book", word2 ="back" - Expected Output: 2
- Justification: Two operations are required: 1) Replace 'o' with 'a', and 2) Replace the second 'o' with 'c'. This changes "book" to "back".
- Input: word1 =
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Valid Parenthesis String
Solution: Edit Distance
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself